package JAVAcollectionsanddatastructures.enumdemo;


//自己写的枚举类都默认继承Enum
public enum TestEnum {

    RED("red", 1), BLACK("black", 3), GREEN("green", 8),
    WHITE("white", 2);

    public String color;
    public int ordinal;

    TestEnum(String color, int ordinal) {
        //super();
        this.color = color;
        this.ordinal = ordinal;
    }

    //构造方法默认是私有的
    private TestEnum() {

    }

   /*TestEnum() {

    }*/

    public static void main3(String[] args) {
        //把字符串 变成对应的枚举对象
        TestEnum testEnum = TestEnum.valueOf("RED");//将普通字符串转换为枚举实例
        System.out.println(testEnum);

        System.out.println(RED.compareTo(GREEN));//比较两个枚举成员在定义时的顺序,默认索引比较

        System.out.println(BLACK.compareTo(RED));
    }


    public static void main2(String[] args) {
        TestEnum[] testEnums = TestEnum.values();//以数组形式返回枚举类型的所有成员  问题：为什么在Enum 的 API 文档中也找不到这个方法？
        for (int i = 0; i < testEnums.length; i++) {
            System.out.println(testEnums[i] + " ->" + testEnums[i].ordinal());//获取枚举成员的索引位置
        }
    }

    public static void main1(String[] args) {
        TestEnum testEnum2 = TestEnum.BLACK;
        switch (testEnum2) {
            case RED:
                System.out.println("red");
                break;
            case BLACK:
                System.out.println("black");
                break;
            case WHITE:
                System.out.println("WHITE");
                break;
            case GREEN:
                System.out.println("GREEN");
                break;
            default:
                break;
        }
    }


}
